package hari4.tes.soal4;

import java.util.*;

class Player implements Comparable{
	public String name;
	public int score;
	
	public Player(){}
	public Player(String name, int score) {
		this.name = name;
		this.score = score;
	}
	
	public String toString() {
		return name + "\t" + score;
	}
	
	public void setName(String name) {
		this.name = name;
	}	
	public void setScore(int score) {
		this.score = score;
	}
	public int compareTo(Object obj) {
		Player prs = (Player) obj;
		if (this.score < prs.score) {
			return 1;
		} else if (this.score > prs.score) {
			return -1;
		}
		return 0;
	}
}

//interface groupPlayer {
//    String add(Player p);
//}
//
//class groupPlayerImpl implements groupPlayer{
//    public String f;
//    List s = new ArrayList<Player>();
//
//    public String add(Player p) {
//
//        if(s.size() < 10 )
//        {
//            if (s.contains(p)) {
//                f = "Player already exist";
//            }
//            else {
//                s.add(p);
//                f = "Player added successfully";
//            }
//        }
//        else
//        {
//            f = "No more player allowed joining the team";
//        }
//       return f;
//
//    }
//
//}

public class HighScore extends Player{
	public static void main(String[] args) {
		System.out.println("High Score");
		
		List player = new ArrayList();
		Player pHarry = new Player("Harry", 190);
		Player pSally = new Player("Sally", 170);
		Player pJohn = new Player("John", 85);
		Player pBond = new Player("Bond", 60);
		Player pHarry2 = new Player("Harry", 200);
		
		player.add(pHarry);
		player.add(pSally);
		player.add(pJohn);
		player.add(pBond);
		player.add(pHarry2);
		
		Collections.sort(player);
		
		int j = 1;
		for (int i = 0; i < player.size(); i++) {
			System.out.println("[" + j + "] " + player.get(i));
			j++;
		}		
		
		System.out.println("Menu");
		System.out.println("(x) Exit");
		System.out.println("(c) Clear List");
		System.out.println("(a) Add Player");
		
		System.out.print("Pilihan :");
	 	String n = BacaKeyboard.bacaString();
		
		
		if (n == "c") {
			player.clear();player.retainAll(player);		
			
		}
		System.out.println(player);
//		else if (n == "c") bersihList();
//		else keluar();
					
	}
}
